package collectionTest;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * create by yongli on 2021-07-10 23:34
 * 原来list的复制如此简单，构造函数或者addAll,而不用Collections工具类
 */

public class CopyTest {
    public static void main(String[] args) {
        int n=4;
        List<Integer> arr = new ArrayList<>();
        for(int i=0;i<n;i++){
            Integer a = (int)(Math.random()*100);

            arr.add((int)(Math.random()*100));
        }
        // size和capacity
        List<Integer> arrCp = new ArrayList<>(arr.size());
        System.out.println(arrCp.size());
        System.out.println(arr.size());
        Collections.copy(arrCp,arr);
        arrCp.set(2,1);

        for (int i = 0; i < arr.size(); i++) {
            System.out.printf("%d ",arr.get(i));
        }
        System.out.println();

        for (int i = 0; i < arr.size(); i++) {
            System.out.printf("%d ",arrCp.get(i));
        }
    }
}
